﻿using System;
using System.Text;
using System.Drawing;

namespace DataCoreTechnologies.Scribe.Business
{
    internal sealed class ColorPreferences
    {
        //Properties
        internal static Color Default
        {
            get
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                return _colorPreferences._topMenu;
            }
            set
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                _colorPreferences._topMenu = value;
            }
        }
        internal static string DefaultHexString
        {
            get
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                return ColorToHexString(_colorPreferences._topMenu);
            }
        }

        internal static Color HighlightedItem
        {
            get
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                return _colorPreferences._selectedItem;
            }
            set
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                _colorPreferences._selectedItem = value;
            }
        }
        internal static string HighlightedHexString
        {
            get
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                return ColorToHexString(_colorPreferences._selectedItem);
            }
        }

        internal static Color EvenRow
        {
            get
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                return _colorPreferences._evenRow;
            }
            set
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                _colorPreferences._evenRow = value;
            }
        }
        internal static string EvenRowHexString
        {
            get
            {
                if (_colorPreferences == null) _colorPreferences = new ColorPreferences();
                return ColorToHexString(_colorPreferences._evenRow);
            }
        }

        //Constructor
        private ColorPreferences()
        {
            //_topMenu = Color.FromArgb(238, 238, 238);
            _topMenu = Color.Blue;
            _selectedItem = Color.FromArgb(0, 51, 153);
            _evenRow = Color.FromArgb(252, 248, 205);
        }

        //Methods
        private static char[] hexDigits = {
         '0', '1', '2', '3', '4', '5', '6', '7',
         '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        private static string ColorToHexString(Color color)
        {
            byte[] bytes = new byte[3];
            bytes[0] = color.R;
            bytes[1] = color.G;
            bytes[2] = color.B;
            char[] chars = new char[bytes.Length * 2];
            for (int i = 0; i < bytes.Length; i++)
            {
                int b = bytes[i];
                chars[i * 2] = hexDigits[b >> 4];
                chars[i * 2 + 1] = hexDigits[b & 0xF];
            }
            return new string(chars);
        }

        //Variables
        private Color _topMenu;
        private Color _selectedItem;
        private Color _evenRow;
        private static ColorPreferences _colorPreferences;
    }
}
